using Microsoft.AspNetCore.Mvc;
using JTZY.Model.Order.Dto;
using JTZY.Model.Order;
using JTZY.Service.Order.IOrderService;
using JTZY.Admin.WebApi.Filters;

//创建时间：2024-12-11
namespace JTZY.Admin.WebApi.Controllers.Order
{
    /// <summary>
    /// 订单货物明细
    /// </summary>
    [Verify]
    [Route("order/Orderdetail")]
    public class OrderdetailController : BaseController
    {
        /// <summary>
        /// 订单货物明细接口
        /// </summary>
        private readonly IOrderdetailService _OrderdetailService;

        public OrderdetailController(IOrderdetailService OrderdetailService)
        {
            _OrderdetailService = OrderdetailService;
        }

        /// <summary>
        /// 查询订单货物明细列表
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        [HttpGet("list")]
        [ActionPermissionFilter(Permission = "orderdetail:list")]
        public IActionResult QueryOrderdetail([FromQuery] OrderdetailQueryDto parm)
        {
            var response = _OrderdetailService.GetList(parm);
            return SUCCESS(response);
        }


        /// <summary>
        /// 查询订单货物明细详情
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpGet("{Id}")]
        [ActionPermissionFilter(Permission = "orderdetail:query")]
        public IActionResult GetOrderdetail(long Id)
        {
            var response = _OrderdetailService.GetInfo(Id);
            
            var info = response.Adapt<OrderdetailDto>();
            return SUCCESS(info);
        }

        /// <summary>
        /// 添加订单货物明细
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [ActionPermissionFilter(Permission = "orderdetail:add")]
        [Log(Title = "订单货物明细", BusinessType = BusinessType.INSERT)]
        public IActionResult AddOrderdetail([FromBody] OrderdetailDto parm)
        {
            var modal = parm.Adapt<Orderdetail>().ToCreate(HttpContext);

            var response = _OrderdetailService.AddOrderdetail(modal);

            return SUCCESS(response);
        }

        /// <summary>
        /// 更新订单货物明细
        /// </summary>
        /// <returns></returns>
        [HttpPut]
        [ActionPermissionFilter(Permission = "orderdetail:edit")]
        [Log(Title = "订单货物明细", BusinessType = BusinessType.UPDATE)]
        public IActionResult UpdateOrderdetail([FromBody] OrderdetailDto parm)
        {
            var modal = parm.Adapt<Orderdetail>().ToUpdate(HttpContext);
            var response = _OrderdetailService.UpdateOrderdetail(modal);

            return ToResponse(response);
        }

        /// <summary>
        /// 删除订单货物明细
        /// </summary>
        /// <returns></returns>
        [HttpPost("delete/{ids}")]
        [ActionPermissionFilter(Permission = "orderdetail:delete")]
        [Log(Title = "订单货物明细", BusinessType = BusinessType.DELETE)]
        public IActionResult DeleteOrderdetail([FromRoute]string ids)
        {
            var idArr = Tools.SplitAndConvert<long>(ids);

            return ToResponse(_OrderdetailService.Delete(idArr));
        }

    }
}